//
//  ChainNewsDetailBottomBar.m
//  Chain
//
//  Created by zhaosh on 2018/4/13.
//  Copyright © 2018年 zhaosh. All rights reserved.
//
#import "ChainNewsDetailBottomBar.h"

@implementation ChainNewsDetailBottomBar

-(instancetype)initWithFrame:(CGRect)frame withCollect:(NSString *)isCollected{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        [self setupSubviews:isCollected];
    }
    return self;
}

-(void)setupSubviews:(NSString *)isCollected{
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 0.5)];
    lineView.backgroundColor=HEXCOLOR(@"#ededed");
    [self addSubview:lineView];
    
    UIButton *commentBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 10,self.width-110, 32)];
    commentBtn.backgroundColor = HEXCOLOR(@"#ededed");
    commentBtn.layer.cornerRadius =16;
    commentBtn.layer.masksToBounds = YES;
    commentBtn.tag=1;
    [commentBtn setTitleColor:HEXCOLOR(@"#999999") forState:UIControlStateNormal];
    commentBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    commentBtn.titleLabel.textAlignment =NSTextAlignmentLeft;
    [commentBtn setTitle:@"我来说两句" forState:UIControlStateNormal];
    [commentBtn addTarget:self action:@selector(bottomBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:commentBtn];
    
    UIButton *favorButton=[[UIButton alloc] initWithFrame:CGRectMake(self.width-70,20, 20, 19)];
    if ([isCollected isEqualToString:@"1"]) {
       [favorButton setBackgroundImage:[UIImage imageNamed:@"detail_collect_selected"] forState:UIControlStateNormal];
    }else{
        [favorButton setBackgroundImage:[UIImage imageNamed:@"detail_collect"] forState:UIControlStateNormal];
    }
    favorButton.tag=2;
    [favorButton addTarget:self action:@selector(bottomBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview: favorButton];
    
    UIButton *shareButton=[[UIButton alloc] initWithFrame:CGRectMake(self.width-35,20, 20, 17)];
    [shareButton setBackgroundImage:[UIImage imageNamed:@"detail_share2"] forState:UIControlStateNormal];
    shareButton.tag=3;
    [shareButton addTarget:self action:@selector(bottomBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview: shareButton];
}

-(void)bottomBtnClicked:(UIButton *)btn{
    if (btn.tag==1) {
        if (self.commentBlock) {
            self.commentBlock(btn);
        }
    }else if (btn.tag==2) {
        if (self.collectBlock) {
            self.collectBlock(btn);
        }
    }else if (btn.tag==3){
        if (self.shareBlock) {
            self.shareBlock(btn);
        }
    }
}
@end
